package com.bao.work.work06;

import com.bao.work.work05.Student;

import java.util.ArrayList;

/**
 * @author baoye
 * @date 2024-07-29/19:40
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<Student> students =new ArrayList<>();
        students.add(new Student("小明",15,66.5));
        students.add(new Student("中明",25,26.5));
        students.add(new Student("大明",35,76.5));
        students.add(new Student("老明",65,56.5));
        students.add(new Student("小古",15,64.5));
        students.add(new Student("中古",25,91.5));
        students.add(new Student("大古",35,96.5));
        students.add(new Student("小月",15,46.5));
        students.add(new Student("中月",25,51.2));
        students.add(new Student("大月",35,55.5));

        System.out.println("最高分的学生:"+getMax(students).getName());
        System.out.println("总分:"+getSum(students));
        System.out.println("平均分:"+getAvg(students));
        System.out.println("不及格的学生信息:");
        printF(students);


    }
    public static Student getMax(ArrayList<Student> list){
        Double max=list.get(0).getScore();
        int index=0;
        for (Student student : list) {
            if(student.getScore()>max){
                index=list.indexOf(student);
            }
        }
        return list.get(index);
    }

    public  static Double getSum(ArrayList<Student> list){
        Double sum=0.0;
        for (Student student : list) {
            sum+=student.getScore();
        }
        return sum;
    }
    public  static Double getAvg(ArrayList<Student> list){
        return getSum(list)/list.size();
    }

    public static void printF(ArrayList<Student> list){
        int count=0;
        for (Student student : list) {
            if (student.getScore() < 60) {
                System.out.println(student.getName()+","+student.getAge()+","+student.getScore());
                count++;
            }
        }
        System.out.println("不及格的人有:"+count+"个");
    }
}
